#define _CRT_SEURE_NO_WARNINGS 1
#include<assert.h>
#include<stdlib.h>
#include<string.h>

int is_palindrome(const char* left, const char* right)
{
	int flag = 1;
	while (left < right)
	{
		if (*left != *right)
		{
			flag = 0;
			break;
		}
		else
		{
			++left;
			--right;
		}
	}
	return flag;
}

char* longestPalindrome(char* s)
{
	assert(s);
	int num = strlen(s);
	int len = num;
	int flag = 0;
	int i = 0;
	while (num > 1)
	{
		for (i = 0; i <= len - num; ++i)
		{
			if (is_palindrome(s + i, s + i + num - 1))
			{
				flag = 1;
				break;
			}
		}
		if (flag)
			break;
		else
		--num;
	}
	
	*(s + i + num) = '\0';
	return s+i;
}

int main()
{
	char s[] = "babad";
	char* ret = longestPalindrome(s);
	puts(ret);
	return 0;
}